package br.mikhas.container.scope;

import java.lang.reflect.Method;

import javassist.util.proxy.MethodHandler;
import br.mikhas.container.factory.BeanFactory;
import br.mikhas.container.factory.BeanFactoryAware;

public class ScopeProxyMethodHandler implements MethodHandler, BeanFactoryAware {

	private BeanFactory beanFactory;

	private String resourceName;

	public Object invoke(Object self, Method thisMethod, Method proceed,
			Object[] args) throws Throwable {

		Object resource = beanFactory.getResource(this.resourceName);

		return thisMethod.invoke(resource, args);
	}

	@Override
	public void setBeanFactory(BeanFactory beanFactory) {
		this.beanFactory = beanFactory;
	}

	public void setResourceName(String name) {
		this.resourceName = name;
	}

}
